#include<bits/stdc++.h>
#define int long long
#define N 200005
using namespace std;
int n;
int v[N],c[N],d[N];
int z,sum;
const int mod=998244353;
void sub(){
    int mx=v[n];
    for(int i=n;i>=1;i--){
        mx=max(mx,v[i]);
        sum=(sum+c[i]*mx%mod)%mod;
    }
    printf("%lld\n",sum);
}
signed main(){
    freopen("b.in","r",stdin);
    freopen("b.out","w",stdout);
    scanf("%lld",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&v[i]);
    for(int i=1;i<=n;i++) scanf("%lld",&c[i]);
    for(int i=1;i<n;i++) scanf("%lld",&d[i]),z+=(d[i]==1);
    if(z==n-1){sub();return 0;}
    for(int i=n-1;i>=1;i--) if(d[i]==1&&v[i]<=v[i+1]) v[i]=v[i+1];
    for(int i=1;i<n;i++){
        if(v[i+1]>=d[i]*v[i]){
            int l=c[i]/d[i];
            c[i]-=d[i]*l;
            c[i+1]+=l;
        }
    }
    for(int i=1;i<=n;i++) sum=(sum+c[i]%mod*v[i]%mod)%mod;
    printf("%lld\n",sum);
    return 0;
}